<cfcomponent hint="Provides functionality to the GetSetCF! Application">

	<cffunction name="init" returntype="GetSetCF">
		<cfreturn this />
	</cffunction>
	
	<cffunction name="getReturnTypes" hint="Returns a list of default returntypes for CFC methods" returntype="any">
		<cfreturn "any,array,binary,boolean,date,guid,numeric,query,string,struct,uuid,void,WEB-INF.cftags.component" />
	</cffunction>
	
	<cffunction name="getStringReturnTypes" hint="Returns a list of string types for CFC methods" returntype="any">
		<cfreturn "date,guid,string,uuid" />
	</cffunction>

	<cffunction name="getAccessValues" hint="Returns a list of access values for CFC methods" returntype="string">
		<cfreturn "private,package,public,remote" />
	</cffunction>
	
	<cffunction name="getReturnTypeSelect" hint="Returns a string which contains the option values for a select" returntype="string">
		<cfargument name="CFCName" hint="The filename of the CFC" required="false" default="">
		<cfargument name="thisVar" hint="The name of the current variable being set" required="false" default="">
		<cfset var thisList = '' />
		<cfset var retValue = "" />
		<cfset var i = 0 />
		<cfset var thisOpt = '' />
		<cfif Len(Trim(Arguments.CFCName)) & Len(Trim(Arguments.thisVar))>
			<cfset thisList = getReturnTypes() & "," & Arguments.thisVar & "," & Arguments.CFCName />
		<cfelse>
			<cfset thisList = getReturnTypes() />
		</cfif>
		
		<cfloop from="1" to="#ListLen(thisList)#" index="i">
			<cfset thisOpt = ListGetAt(thisList, i) />
			<cfif StructKeyExists(Form, "DefaultReturnType") AND thisOpt EQ Form.DefaultReturnType>
				<cfset retValue = retValue & '<option value="#thisOpt#" selected>#thisOpt#</option>' & getNL() />
			<cfelse>
				<cfset retValue = retValue & '<option value="#thisOpt#">#thisOpt#</option>' & getNL() />
			</cfif>
		</cfloop>
		<!--- <cfset retValue = '<option value="" selected>ignore</option>' & retValue /> --->
		<cfreturn retValue />
	</cffunction>
	
	<cffunction name="getOpenCFC" hint="Returns a string which opens the cfcomponent tag">
		<cfargument name="CFCDesc" hint="the string to be applied as a hint" default="" />
		<cfargument name="FieldList" hint="The list of fields being used to populate this CFC" default="" />
		<cfset var retString = '' />
		<cfif Len(Trim(CFCDesc))>
			<cfset retString = '<cfcomponent hint="#Arguments.CFCDesc#">' & getNL() />
		<cfelse>
			<cfset retString = '<cfcomponent>' & getNL() />
		</cfif>
		<cfreturn retString />
	</cffunction>
	
	<cffunction name="getCloseCFC" hint="Returns a string which opens the cfcomponent tag">
		<cfargument name="FieldList" hint="The list of fields being used to populate this CFC" default="" />
		<cfset var retString = '' />
		<cfset retString = getNL() & getMetaMethod(FieldList) />
		<cfset retString = retString & getNL() & "</cfcomponent>" />
		<cfreturn retString />
	</cffunction>
	
	<cffunction name="getInitMethod" hint="Returns a string which creates an init method">
		<cfargument name="CFCName" hint="The name of the CFC" type="string" required="true">
		<cfset var retString = '' />
		<!--- <cfset retString = getTab() & '<cffunction name="init" returntype="#Arguments.CFCName#">' & getNL() /> --->
		<cfset retString = getTab() & '<cffunction name="init" returntype="any">' & getNL() />
		<cfset retString = retString & getTab(2) & '<cfreturn this />' & getNL() />
		<cfset retString = retString & getTab(1) & "</cffunction>" & getNL() />
		<cfreturn retString />
	</cffunction>
	
	<cffunction name="getOpenInitMethod" hint="Returns a string which creates an init method">
		<cfargument name="CFCName" hint="The name of the CFC" type="string" required="true">
		<cfset var retString = '' />
		<!--- <cfset retString = getTab() & '<cffunction name="init" returntype="#Arguments.CFCName#">' & getNL() /> --->
		<cfset retString = getTab() & '<cffunction name="init" returntype="WEB-INF.cftags.component">' & getNL() />

		<cfreturn retString />
	</cffunction>
	
	<cffunction name="getCloseInitMethod" hint="Returns a string which creates an init method">
		<cfargument name="CFCName" hint="The name of the CFC" type="string" required="true">
		<cfset var retString = '' />
		<cfset retString = retString & getTab(2) & '<cfreturn this />' & getNL() />
		<cfset retString = retString & getTab(1) & "</cffunction>" & getNL() />
		<cfreturn retString />
	</cffunction>
	
	<cffunction name="getInitSetter" hint="Returns a string with an init method call to a setter method">
		<cfargument name="VarName" hint="Name of the variable to set" required="true" />
		<cfargument name="VarReturnType" hint="The returntype of this getter" type="string" default="void" />
		<cfargument name="VarDefault" default="" hint="Default value for this param" />
		<cfset var retString = "" />
		<cfset var isStringType = ListFindNoCase(getStringReturnTypes(), Arguments.VarReturnType, ",") />
		<cfif isStringType>
			<cfset retString = getTab(2) & '<cfset set' & Arguments.VarName & '("' & VarDefault & '") />' & getNL() />
		<cfelse>
			<cfset retString = getTab(2) & '<cfset set' & Arguments.VarName & '(' & VarDefault & ') />' & getNL() />
		</cfif>
		<cfreturn retString />
	</cffunction>
	
	<cffunction name="getGetterMethod" hint="Returns a string which creates a getter method">
		<cfargument name="VarName" hint="Name of the variable to set" required="true" />
		<cfargument name="VarReturnType" hint="The returntype of this getter" type="string" default="void" />
		<cfargument name="VarHint" default="the value for #Arguments.VarName#" />
		<cfset var retString = '' />
		<cfset retString = getNL() & getTab() & '<cffunction name="get#VarName#" returntype="#Arguments.VarReturnType#" hint="Returns #Arguments.VarHint#" output="false">' & getNL() />
		<cfset retString = retString & getTab(2) & '<cfreturn Variables.#VarName# />' & getNL() />
		<cfset retString = retString & getTab(1) & "</cffunction>" & getNL() />
		<cfreturn retString />
	</cffunction>
	
	<cffunction name="getMetaMethod" hint="Generates a meta method which stores data to reuse in GetSetCF">
		<cfargument name="FieldList" hint="The list of fields being used to populate this CFC" default="" />
		<cfset var retString = '' />
		<cfset retString = getTab() & '<cffunction name="getGetSetCFMetaInfo" returntype="string" access="private" hint="Stores meta info for GetSetCF so that you can later edit a previously generated component">' & getNL() />
		<cfset retString = retString & getTab(2) & '<cfreturn "' & FieldList & '" />' & getNL() />
		<cfset retString = retString & getTab(1) & "</cffunction>" & getNL() />
		<cfreturn retString />
	</cffunction>
	
	<cffunction name="getSetterMethod" hint="Returns a string which opens the cfcomponent tag">
		<cfargument name="VarName" hint="Name of the variable to set" required="true" />
		<cfargument name="VarReturnType" hint="The returntype of this getter" type="string" default="void" />
		<cfargument name="VarHint" default="the value for #Arguments.VarName#" />
		<cfargument name="VarDefault" default="" />
		<cfset var retString = '' />
		<cfset retString = getNL() & getTab() & '<cffunction name="set#VarName#" returntype="void" hint="Sets #Arguments.VarHint#" output="false">' & getNL() />
		<cfif VarName EQ VarReturnType>
			<cfset retString = retString & getTab(2) & '<cfset Variables.#VarName# = CreateObject("component", "#VarName#").init() />' & getNL() />
		<cfelse>
			<cfset retString = retString & getTab(2) & '<cfargument name="#VarName#" hint="The value of #VarName#" type="#VarReturnType#" required="true" />' & getNL() />
			<cfset retString = retString & getTab(2) & '<cfset Variables.#VarName# = Arguments.#VarName# />' & getNL() />
		</cfif>
		<cfset retString = retString & getTab(1) & "</cffunction>" & getNL() />
		<cfreturn retString />
	</cffunction>
	
	<cffunction name="getTab">
		<cfargument name="Qty" hint="How many of this character to return" type="numeric" default="1" />
		<cfset var retValue = '' />
		<cfset var thisChar = Chr(9) />
		<cfset var i = 0 />
		<cfloop from="1" to="#Arguments.Qty#" index="i"><cfset retValue = retValue & thisChar /></cfloop>
		<cfreturn retValue />
	</cffunction>
	
	<cffunction name="getNL">
		<cfargument name="Qty" hint="How many of this character to return" type="numeric" default="1" />
		<cfset var retValue = '' />
		<cfset var thisChar = Chr(13) & Chr(10) />
		<cfset var i = 0 />
		<cfloop from="1" to="#Arguments.Qty#" index="i"><cfset retValue = retValue & thisChar /></cfloop>
		<cfreturn retValue />
	</cffunction>

</cfcomponent>